* ASI 93 94 cleanup

use "$data\asi9394.dta", clear
keep v5 v11a v3 v16 v17 v18 v19 v20 v24 v26 v28 v29 v35 v37 v38 v39 v40 v41 v50 v51 v49 v52 v66 v67 v68 v88 v57 v58 v93 v108

g year = 1993

/* some of these may be wrong!*/

rename v24 ruralurbancode

rename v5 industrycode
rename v3 statecode
rename v11a multiplier
rename v16 ownershipcode
rename v17 orgcode
rename v18 managcode
rename v19 schemecode
rename v20 districtcode
rename v26 setup
rename v28 openclose
rename v29 powercode
rename v35 factories
rename v37 closingvalueland
rename v38 fixedcapitalop
rename v39 fixedcapitalcl
rename v40 landrental
rename v41 totalrent
rename v50 workers
rename v49 mandays
rename v51 workers_2
rename v88 workerswages
rename v66 totaloutput
rename v67 depreciation
rename v108 electricity
rename v57 fuel
rename v58 materials
rename v68 valueadded
rename v93 profits


drop if openclose==1

/* undoing multiplier madness*/
replace multiplier=multiplier/100

/* generating 3-digit industry codes*/
ge indcode_str=string(industrycode)
replace indcode_str=substr(indcode_str, 1,3)
destring indcode_str, generate(indcode_3dig)
drop indcode_str
label var indcode_3dig "3 dig industry code"

rename indcode_3dig nic87code

/* creating a 2-digit code */
ge nic87code_str=string(nic87code)
replace nic87code_str=substr(nic87code_str, 1,2)
destring nic87code_str, generate(nic87code_2dig)
drop nic87code_str
label var nic87code_2dig "2 dig NIC87 code"

/* creating a 1-digit code */
ge nic87code_str=string(nic87code)
replace nic87code_str=substr(nic87code_str, 1,1)
destring nic87code_str, generate(nic87code_1dig)
drop nic87code_str
label var nic87code_1dig "1 dig NIC87 code"


 
/* price deflator*/
sort nic87code
merge nic87code using "$data\indexfinal.dta"
tab _merge
keep if _merge==3
drop _merge

g asicode99 = statecode*100 + districtcode
sort asicode99 year

/* generating factories variable*/
drop factories
ge factories=1

